package cn.hh.wechatkit.handler;

import cn.hh.WxKit;
import cn.hh.wechatkit.data.postdata.message.meta_SendTemplateMsgData;
import cn.hh.wechatkit.data.returndata.Meta_RMsg_Base;
import cn.hh.wechatkit.exception.Wx_Exception_GetTokenFailed;
import cn.hh.wechatkit.exception.Wx_Exception_InvalidJsonParse;
import cn.hh.wechatkit.exception.Wx_Exception_InvalidParam;
import cn.hh.wechatkit.exception.Wx_Exception_InvalidResponse;
import cn.hh.wechatkit.pojo.token.WxToken_AccessToken;
import cn.hh.wechatkit.pojo.token.WxToken_ApiTicketToken;
import cn.hh.wechatkit.pojo.token.WxToken_AuthoAccessToken;
import cn.hh.wechatkit.pojo.token.WxToken_JsApiToken;
import cn.hh.wechatkit.pojo.token.WxApp_OpenIdSession;
import cn.hh.wechatkit.pojo.user.Wx_UnionInfo;

import java.io.IOException;

/**
 * Created by hh23485 on 2017/6/24.
 */
public class WxTemplate {

    /**
     * 封装WxTemplate - 用户组件
     */
    public Wx_UnionInfo getUnionInfoByCode(String code) throws Wx_Exception_GetTokenFailed, Wx_Exception_InvalidResponse, Wx_Exception_InvalidJsonParse, IOException {
        return WxKit.$wx().wxCom_user().getUnionInfoByCode(code);
    }

    public WxApp_OpenIdSession getOpenIdSessionByCode(String js_code) {
        return WxKit.$wx().wxCom_token().getOpenIdSession(js_code);
    }

    public Wx_UnionInfo getUnionInfoByOpenId(String openId) throws Wx_Exception_GetTokenFailed, Wx_Exception_InvalidResponse, Wx_Exception_InvalidJsonParse, IOException {
        return WxKit.$wx().wxCom_user().getUnionInfoByOpenId(openId);
    }

    public String getAuthoUrl(String redirectUrl,int scope,String state) throws Wx_Exception_InvalidParam {
        return WxKit.$wx().wxCom_user().getAuthoUrl(redirectUrl,scope,state);
    }

    /**
     * 封装WxTemplate - Token组件
     */

    public WxToken_AccessToken getAccessToken() throws Wx_Exception_GetTokenFailed, IOException, Wx_Exception_InvalidResponse, Wx_Exception_InvalidJsonParse {
        return WxKit.$wx().wxCom_token().getAccessToken();
    }

    /**
     * 封装WxTemplate - Token组件 小程序
     */

    public WxToken_AccessToken getAppAccessToken() throws Wx_Exception_GetTokenFailed, IOException, Wx_Exception_InvalidResponse, Wx_Exception_InvalidJsonParse {
        return WxKit.$wx().wxCom_token().getAppAccessToken();
    }

    public WxToken_ApiTicketToken getApiTicketToken() throws Wx_Exception_GetTokenFailed, IOException, Wx_Exception_InvalidResponse, Wx_Exception_InvalidJsonParse {
        return WxKit.$wx().wxCom_token().getApiTicketToken();
    }

    public WxToken_AuthoAccessToken getAuthoAccessToken(String code) throws Wx_Exception_GetTokenFailed, IOException, Wx_Exception_InvalidResponse, Wx_Exception_InvalidJsonParse {
        return WxKit.$wx().wxCom_token().getAuthoAccessToken(code);
    }

    public WxToken_JsApiToken getJsApiToken() throws Wx_Exception_GetTokenFailed, Wx_Exception_InvalidResponse, Wx_Exception_InvalidJsonParse, IOException {
        return WxKit.$wx().wxCom_token().getJsApiToken();
    }

    /**
     * 封装WxTemplate - Message组件
     */
    public Meta_RMsg_Base sendTemplateMsg(meta_SendTemplateMsgData msgData) {
        return WxKit.$wx().wxCom_message().sendTemplateMsg(msgData);
    }
}
